package com.jp.algorithm.recursive;

public class Hano {

    static int m = 0;// 标记移动次数

    public static void move(int diskNum, char N, char M) {
        System.out.println("第" + (++m) + " 次移动 : " + " 把 " + diskNum + " 号圆盘从 " + N + " ->移到->  " + M);
    }

    public static void hano(int n, char src, char tmp, char dest) {
        if (n == 1) //最上层圆盘直接从 src移动到dest
            move(1, src, dest);
        else {
            hano(n - 1, src, dest, tmp);  //将n-1号及以上的圆盘从src移动到tmp，dest做中转
            move(n, src, dest);//将n号圆盘从src移动到dest
            hano(n - 1, tmp, src, dest);//将n-1号及以上的圆盘从tmp移动到dest，src做中转
        }
    }

    public static void main(String[] args) {
        char A = 'A';
        char B = 'B';
        char C = 'C';
        hano(20, A, B, C);
    }
}
